package com.xiaodou.mjf.infrastructure.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xiaodou.mjf.infrastructure.common.utils.DateUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Version;
import java.util.Date;

@MappedSuperclass
public class DataEntity extends IdEntity{

    protected Integer status;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="create_time")
    protected Date createTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="modify_time")
    protected Date modifyTime;
    @Version
    @JsonIgnore
    protected Integer version;

    public DataEntity() {
        this.status = NORMAL;
    }

    @PrePersist
    public void prePersist(){
        super.prePersist();
        this.createTime = DateUtils.getCurrentTime();
    }

    @PreUpdate
    public void preUpdate(){
        this.modifyTime = DateUtils.getCurrentTime();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * 正常
     */
    public final static Integer NORMAL = 0;
    /**
     * 删除
     */
    public final static Integer DELETE = 1;
    /**
     * 等待审核
     */
    public final static Integer WAIT_AUDIT = 2;
    /**
     * 审核失败
     */
    public final static Integer REJECT = 3;
}
